/*
 * EpsilonGrid.h
 *
 *  Created on: Mar 29, 2012
 *      Author: marchi
 */

#ifndef EPSILONGRID_H_
#define EPSILONGRID_H_
#include "Epsilon.h"

namespace EpsilonNS {

class EpsilonGrid: public Epsilon {
protected:
	static Matrix zero;
	Dvect xRef;
	array3<Matrix> D;
	array3<Matrix> G;
	array3<Dvect> E;
	array3<Dvect> M;
	array3<Matrix> eps;
	virtual void WriteIt(std::ofstream &) const;
	virtual void ReadIt(std::ifstream &);
public:
	EpsilonGrid();
	virtual ~EpsilonGrid();
	virtual bool operator()(Polarization &, Field &, Matrix & M=zero, Voronoi * b=NULL);
	virtual void Rdf(const double, const double);
	virtual void Allocate(){
		try{if(!(nnx || nny || nnz)) throw " Trying to allocate, but at least "
				"one of the dimensions is zero ";}
		catch(const char * s){
			std::cout << s << std::endl;
			exit(1);
		}

		D.Allocate(nnx,nny,nnz);
		G.Allocate(nnx,nny,nnz);
		M.Allocate(nnx,nny,nnz);
		E.Allocate(nnx,nny,nnz);
		eps.Allocate(nnx,nny,nnz);
		D=0.0;
		G=0.0;
		M=0.0;
		E=0.0;
		eps=0.0;
	}
	virtual void Deallocate(){
		D.Deallocate();
		G.Deallocate();
		M.Deallocate();
		E.Deallocate();
		eps.Deallocate();
	}
	void setxRef(Dvect & x){is_xRefset=true;xRef=x;};
	void setxRef(Dvect x){is_xRefset=true;xRef=x;};
};

} /* namespace EpsilonNS */
#endif /* EPSILONGRID_H_ */
